

//
//  NetRequest+community.m
//  DogeLegs
//
//  Created by 宋华 on 2017/8/20.
//  Copyright © 2017年 宋华. All rights reserved.
//

#import "NetRequest+community.h"
#import "NoteMode.h"

@implementation NetRequest (community)

/*
 @brief 获取社区帖子
 @param success 成功回调
 @param fail 失败回调
 */
- (NSURLSessionDataTask *)getNotelistDictionary:(NSDictionary *)params
                                        success:(void (^)(NSMutableArray *orderList,NSInteger totalCount,NSInteger totalPages))success
                                           fail:(void (^)(RequestError *error))fail {
    NSURLSessionDataTask *dataTask = [self postDataFromURLScheme:kNotelistUrl
                                                paramsDictionary:params
                                                interfaceVersion:nil
                                                         success:^(id data, BOOL isSuccess, RequestError *msg) {
                                                             if (isSuccess) {//需要实现
                                                                 NSMutableArray *nodelists = [NoteMode     noteModeFromData:data];
                                                                 if (success) {
                                                                     success(nodelists,0,100);
                                                                 }
                                                                 
                                                             }else {
                                                                 fail(msg);
                                                                 
                                                             }
                                                         }fail:^(RequestError *errMsg) {
                                                             fail(errMsg);
                                                             
                                                         }];
    
    return dataTask;

}


/*
 @brief 添加帖子
 @param success 成功回调
 @param fail 失败回调
 */
- (NSURLSessionDataTask *)postNoteDone:(NSDictionary *)params
                               success:(void (^)(BOOL isSuccess))success
                                  fail:(void (^)(RequestError *error))fail {
    NSURLSessionDataTask *dataTask = [self postDataFromURLScheme:kPostNoteUrl
                                                paramsDictionary:params
                                                interfaceVersion:nil
                                                         success:^(id data, BOOL isSuccess, RequestError *msg) {
                                                             if (isSuccess) {
                                                                 if (success) {
                                                                     success(isSuccess);
                                                                 }
                                                             }else {
                                                                 fail(msg);
                                                                 
                                                             }
                                                         }fail:^(RequestError *errMsg) {
                                                             fail(errMsg);
                                                             
                                                         }];
    
    return dataTask;
}

/*
 @brief 删除帖子
 @param success 成功回调
 @param fail 失败回调
 */
- (NSURLSessionDataTask *)deleteNoteDone:(NSDictionary *)params
                                 success:(void (^)(BOOL isSuccess))success
                                    fail:(void (^)(RequestError *error))fail {
    NSURLSessionDataTask *dataTask = [self postDataFromURLScheme:kDeleteNoteUrl
                                                paramsDictionary:params
                                                interfaceVersion:nil
                                                         success:^(id data, BOOL isSuccess, RequestError *msg) {
                                                             if (isSuccess) {
                                                                 if (success) {
                                                                     success(isSuccess);
                                                                 }
                                                             }
                                                             else {
                                                                 fail(msg);
                                                                 
                                                             }
                                                         }fail:^(RequestError *errMsg) {
                                                             fail(errMsg);
                                                             
                                                         }];
    
    return dataTask;
}

/*
 @brief 添加评论
 @param success 成功回调
 @param fail 失败回调
 */
- (NSURLSessionDataTask *)addNoteComment:(NSDictionary *)params
                                 success:(void (^)(BOOL isSuccess))success
                                    fail:(void (^)(RequestError *error))fail {
    NSURLSessionDataTask *dataTask = [self postDataFromURLScheme:kAddNoteCommentUrl
                                                paramsDictionary:params
                                                interfaceVersion:nil
                                                         success:^(id data, BOOL isSuccess, RequestError *msg) {
                                                             
                                                             if (isSuccess) {
                                                                 if (success) {
                                                                     success(isSuccess);
                                                                 }
                                                             }
                                                                 
                                                                 else {
                                                                     fail(msg);
                                                                     
                                                                 }
                                                         }fail:^(RequestError *errMsg) {
                                                             fail(errMsg);
                                                             
                                                         }];
    
    return dataTask;
}



/*
 @brief 删除评论
 @param success 成功回调
 @param fail 失败回调
 */
- (NSURLSessionDataTask *)deleteNoteComment:(NSDictionary *)params
                                    success:(void (^)(BOOL isSuccess))success
                                       fail:(void (^)(RequestError *error))fail {
    NSURLSessionDataTask *dataTask = [self postDataFromURLScheme:kDeleteNoteCommentUrl
                                                paramsDictionary:params
                                                interfaceVersion:nil
                                                         success:^(id data, BOOL isSuccess, RequestError *msg) {
                                                             if (isSuccess) {
                                                                 if (success) {
                                                                     success(isSuccess);
                                                                 }
                                                                 
                                                             }else {
                                                                 fail(msg);
                                                                 
                                                             }
                                                         }fail:^(RequestError *errMsg) {
                                                             fail(errMsg);
                                                             
                                                         }];
    
    return dataTask;
}

@end
